<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2025/2/24
 * Time: 9:29
 */

namespace app\modules\setting\controllers\auth;


use app\common\controllers\AdminOptionsController;
use app\common\helper\CommonHelper;
use app\modules\setting\configs\auth\SampleConfig;
use app\modules\setting\models\seller\EtcOfficeProductSelectedSearch;
use yii\helpers\ArrayHelper;
use Yii;

class SampleController extends AdminOptionsController
{
    /**
     * @return array
     * 列表数据
     */
    public function actionIndex()
    {
        try {
            $searchModel = new EtcOfficeProductSelectedSearch();
            $dataProvider = $searchModel->searchSample(Yii::$app->request->queryParams);
            $data = $dataProvider->getModels();
            $data = array_map(function($item){
                $re=[];
                if(is_object($item)){
                    $re= $item->toArray();
                }
                $re['product_base'] = $this->product_base($item);
                $re['seller_info'] = $this->seller_info($item);
                $re['office_info'] = $this->office_info($item);
                $re['product_id'] = CommonHelper::getProductNameById($item['product_id']);
                return $re;
            },$data);
            return ArrayHelper::merge(["data" =>$data, "pagination" => $dataProvider->getPagination()],SampleConfig::configIndex());
        }catch (\Throwable $e){
            return ["ok" => false,"msg" => $e->getMessage(),"code" => 401];
        }
    }

    private function product_base($item){
        $str ="";
        $product = $item['product'];
        $str .= "<p>价格：$ {$product['price']}</p>";
        $str .= "<p>达人佣金比例：{$product['creator_commission_percent']}%</p>";
        $str .= "<p>商家佣金比例：{$product['seller_commission_percent']}%</p>";
        $str .= "<p>星级：{$product['product_rating']}</p>";
        $str .= "<p>评论：{$product['product_review_count']}</p>";
        $str .= "<p>出售数：{$product['product_sales']}</p>";
        $str .= "<p><a href='{$product['link']}' target='_blank'>分享链接</a></p>";
        $str .= "<p><a href='{$product['product_link']}' target='_blank'>产品链接</a></p>";

        return $str;
    }

    private function seller_info($item){
        $str ="";
        $product = $item['product'];
        $str .= "<p>产品卖点：{$product['seller_info']}</p>";
        $str .= "<p>使用场景：{$product['use_info']}</p>";
        $str .= "<p>爆款视频链接：{$product['video_info']}</p>";

        return $str;
    }
    private function office_info($item){
        $str ="";
        $str .= "<p>申请时间：{$item['apply_time']}</p>";
        $str .= "<p>发货状态：{$item['send_status']}</p>";
        $str .= "<p>发货时间：{$item['send_time']}</p>";
        $str .= "<p>发样数量：{$item['send_sample_num']}</p>";
        $str .= "<p>发货单号：{$item['send_code']}</p>";
        $str .= "<p>拍摄状态：{$item['video_status']}</p>";
        $str .= "<p>拍摄开始时间：{$item['video_start_time']}</p>";

        return $str;
    }
}